<script setup lang="ts">
import {
  downloadByOnlineUrl,
  downloadByBase64,
  downloadByData,
  downloadByUrl
} from "@pureadmin/utils";
import axios from "axios";

defineOptions({
  name: "Download"
});

const base64 =
  "";

function down() {
  axios
    .get("https://pure-admin.github.io/pure-admin-doc/img/pure.png", {
      responseType: "blob"
    })
    .then(({ data }) => {
      downloadByData(data, "test-data.png");
    });
}
</script>

<template>
  <el-card shadow="never">
    <template #header>
      <span class="font-medium">文件下载功能</span>
    </template>
    <div class="flex flex-wrap">
      <el-button
        @click="
          downloadByOnlineUrl(
            'https://pure-admin.github.io/pure-admin-doc/img/pure.png',
            'test-url.png'
          )
        "
      >
        下载在线图片
      </el-button>

      <el-button @click="downloadByBase64(base64, 'test-base64.png')">
        基于 base64 下载图片
      </el-button>

      <el-button
        @click="
          downloadByUrl(
            'https://github.com/xiaoxian521/xiaoxian521/archive/refs/heads/main.zip',
            'xiaoxian521.zip'
          )
        "
      >
        根据文件地址下载文件
      </el-button>

      <el-button @click="down"> 根据后台接口文件流下载 </el-button>
    </div>
  </el-card>
</template>
